Hi, im new to Umbraco, but i have worked with .NET and C# up to now.
Atm im having a problem displaying an image from the media picker, i realize that its a common issue, and i have searched the web for a solution.
The issue:
I have a tab called Submenu, within it there is a property with the alias 'submenuImage01' with the type set as Media picker. I realize that this will get me the ID of the image.
I want to display the image set as submenuImage01.
I've been working in within the xslt editor, and havent yet been able to fetch the correct data.
The difference is that you are saying if the media picker IS empty, then render the image. But it should of course be if the media picker IS NOT empty, then render the image.
The reason for your trouble is that the code you posted is using the old XML schema, which is not used since Umbraco 4.5 came out. It can howeber be changed in the umbracoSettings.config to use the old schema. But that's probably out of scope for this topic :-)
But new users to Umbraco often (and very understandably) gets confused about this, since they find many XSLT examples, which has been written for version of Umbraco earlier than 4.5.
So what you need to do is to alter the code to this
System.Xml.Xsl.XslLoadException: String literal was not closed.
...urrentPage/photo1,0)/umbracoFile -->'}<-- An error occurred at
C:\projects\HomeNow\Main\HomeNow\xslt\634323250997212466_temp.xslt(17,1).
at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String
fileName, String oldName, String fileContents, Boolean ignoreDebugging)
I am a absolute noob when it comes to XLST. Sorry.
Show image with mediapicker {newbie}
Hi, im new to Umbraco, but i have worked with .NET and C# up to now.
Atm im having a problem displaying an image from the media picker, i realize that its a common issue, and i have searched the web for a solution.
The issue:
I have a tab called Submenu, within it there is a property with the alias 'submenuImage01' with the type set as Media picker. I realize that this will get me the ID of the image.
I want to display the image set as submenuImage01.
I've been working in within the xslt editor, and havent yet been able to fetch the correct data.
This is my code as it is now:
<xsl:template match="/">
<xsl:if test="$currentPage/data[@alias='submenuImage01'] = ''">
<img src="{umbraco.library:GetMedia($currentPage/data[@alias='submenuImage01'],0)/data[@alias='umbracoFile']}" />
</xsl:if>
</xsl:template>
Thanks in advance
Hi Martin
Which version of Umbraco are you using? Or actually I'd like to know which version of the XML schema you are using.
If you are using the "new" XML schema please try this snippet:
<xsl:if test="$currentPage/submenuImage01 != ''">
<img src="{umbraco.library:GetMedia($currentPage/submenuImage01,0)/umbracoFile}" />
</xsl:if>
/Kim A
Ohh and I can just see another small error if you are actually using the legacy schema. Then you need to change this:
<xsl:if test="$currentPage/data[@alias='submenuImage01'] = ''">
to this:
<xsl:if test="$currentPage/data[@alias='submenuImage01'] != ''">
The difference is that you are saying if the media picker IS empty, then render the image. But it should of course be if the media picker IS NOT empty, then render the image.
/Kim A
Im using Umbraco 4.6.1
I made the change, since it should ofc only load the img if there is one.
Here is my xsl document.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:template match="/">
<xsl:if test="$currentPage/data[@alias='submenuImage01'] != ''">
<img src="{umbraco.library:GetMedia($currentPage/data[@alias='submenuImage01'],0)/data[@alias='umbracoFile']}" />
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Thanks for the quick response
Hi Martin
The reason for your trouble is that the code you posted is using the old XML schema, which is not used since Umbraco 4.5 came out. It can howeber be changed in the umbracoSettings.config to use the old schema. But that's probably out of scope for this topic :-)
But new users to Umbraco often (and very understandably) gets confused about this, since they find many XSLT examples, which has been written for version of Umbraco earlier than 4.5.
So what you need to do is to alter the code to this
<xsl:if test="$currentPage/submenuImage01 != ''">
<img src="{umbraco.library:GetMedia($currentPage/submenuImage01,0)/umbracoFile'}" />
</xsl:if>
This should be working I think.
/Jan
That worked.. (deleted the ' after umbracoFile')
Thanks for the help guyes.
Guys, I also need to get an image (well, several images back from the media picker. using the above code, and trying the fix, doesn't work for me:
gives me errors
Error occured
System.Xml.Xsl.XslLoadException: String literal was not closed.
...urrentPage/photo1,0)/umbracoFile -->'}<-- An error occurred at C:\projects\HomeNow\Main\HomeNow\xslt\634323250997212466_temp.xslt(17,1).
at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String oldName, String fileContents, Boolean ignoreDebugging)
I am a absolute noob when it comes to XLST. Sorry.
Ooops, ignore me completely! It did work, I missed the comment before mine about removing the '
final code for reference:
is working on a reply...